package com.fengmi.controller;

import com.fengmi.entity.MallGoodsTemplate;
import com.fengmi.service.MallGoodsTemplateService;
import com.fengmi.vo.InfoResult;
import com.fengmi.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author: 施俊豪
 * Date: 2022/1/20 16:27
 * Note: 商品模板控制器
 */
@CrossOrigin
@Api(description = "商品模板控制器")
@RequestMapping("template")
@RestController
public class MallGoodsTemplateController {
    @Autowired
    private MallGoodsTemplateService mallGoodsTemplateService;

    @ApiOperation("分页+条件查询商品模板")
    @RequestMapping("/findTemplates")
    public PageResult<MallGoodsTemplate> findTemplates(@ApiParam("查询条件") @RequestBody MallGoodsTemplate template,
                                                       @ApiParam("当前页数")@RequestParam(value = "pageNum",defaultValue = "1")String pageNum,
                                                       @ApiParam("每页显示记录数")@RequestParam(value = "pageSize",defaultValue="5")String pageSize,
                                                       @RequestHeader("token")String token){
        System.out.println("分页+条件查询商品模板的token:"+token);
        return mallGoodsTemplateService.findTemplates(template,pageNum,pageSize);
    }

    @ApiOperation("添加商品模板")
    @RequestMapping("/addTemplate")
    public InfoResult addTemplate(@ApiParam("添加参数") @RequestBody MallGoodsTemplate template,
                                  @RequestHeader("token")String token){
        System.out.println("添加商品模板的token:"+token);
        return mallGoodsTemplateService.InsertTemplate(template);
    }

    @ApiOperation("修改商品模板")
    @PutMapping("/updateTempalte")
    public InfoResult updateTemplate(@ApiParam("修改参数") @RequestBody MallGoodsTemplate template,
                                     @RequestHeader("token")String token){
        System.out.println("修改商品模板的token:"+token);
        return mallGoodsTemplateService.updateTemplate(template);
    }

    @ApiOperation("删除商品模板")
    @DeleteMapping("/delTemplate")
    public InfoResult deleteTemplate(@ApiParam("删除的参数")@RequestBody Integer[] ids,
                                     @RequestHeader("token") String token){
        System.out.println("删除商品模板的token:"+token);
        return  mallGoodsTemplateService.delTmplates(ids);
    }

    @ApiOperation("查询所有的商品模板")
    @RequestMapping("/findTempAll")
    public InfoResult findTempAll(){
        return mallGoodsTemplateService.findTemAll();
    }
}
